package com.lingx.web.api.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.lingx.model.impl.DefaultEntity;
import com.lingx.service.ModelService;
import com.lingx.utils.Utils;
import com.lingx.web.api.IApi;
@Component
public class Api9005 extends AbstractDevApi implements IApi{
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private ModelService modelService;
	@Value("#{configs['database.name']}")
	private String table_schema="lingx";
	@Override
	public int getApiCode() {
		return 9005;
	}
	@Override
	public String getApiName() {
		return "创建表模型";
	}
	@Override
	public Map<String, Object> api(Map<String, Object> param) {
		Map<String,Object> ret=IApi.getRetMap(1, "操作成功");
		String code=param.get("code").toString();
		String name=param.get("name").toString();
		String idtype=param.get("idtype").toString();
		DefaultEntity dm=this.modelService.createDefaultModel(code, name, "lingx.com", Integer.parseInt(idtype), table_schema);
		this.modelService.save(dm);
		if(jdbcTemplate.queryForObject("select count(*) from tlingx_entity where code=?",Integer.class,code)==0){
			jdbcTemplate.update("insert into tlingx_entity(id,name,code,type,status,app_id,create_time)values(uuid(),?,?,1,1,?,?)",name,code,"335ec1fc-1011-11e5-b7ab-74d02b6b5f61",Utils.getTime());
		}
		return ret;
	}

}
